package cn.huaqingcheng.tianshu.core.uc.model;

import cn.huaqingcheng.tianshu.common.core.JsonTool;
import cn.huaqingcheng.tianshu.common.core.model.AttributeMap;
import cn.huaqingcheng.tianshu.common.core.model.CommonConvert;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 通用设置
 */
@Data
@Accessors(chain = true)
public class GeneralSetting {

    /**
     * 拖拽
     */
    private Boolean enableDrag;

    /**
     * 显示新增按钮
     */
    private Boolean showCreateBtn;

    /**
     * 锁定布局: 禁止拖拽排序, 编辑, 删除. 不影响新增
     */
    private Boolean lockLayout;

    public static GeneralSetting of(AttributeMap<Object> value) {
        return JsonTool.copy(value, GeneralSetting.class);
    }


    public static GeneralSetting newDefault() {
        return new GeneralSetting()
                .setEnableDrag(Boolean.TRUE)
                .setShowCreateBtn(Boolean.TRUE)
                .setLockLayout(Boolean.FALSE);
    }

    public AttributeMap<Object> toMap() {
        return CommonConvert.INSTANCE.toMap(JsonTool.toJson(this));
    }

}
